/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sessionbean;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import supportlearning.entities.Account;

/**
 *
 * @author Huy
 */
@Stateless
public class AccountFacade extends AbstractFacade<Account> implements AccountFacadeLocal {

    @PersistenceContext(unitName = "EprojectCMSSupportLearning-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public List<Account> findbyRoleID(int i) {
        List<Account> listac = new ArrayList<Account>();
        Query q = em.createQuery("SELECT a FROM Account a WHERE a.cMSRole.roleId = :roleid AND a.status = :b");
        q.setParameter("roleid", i);
         q.setParameter("b", true);
        listac = q.getResultList();
        return listac;
    }
       public List<Account> findbyRoleIDAll(int i) {
        List<Account> listac = new ArrayList<Account>();
        Query q = em.createQuery("SELECT a FROM Account a WHERE a.cMSRole.roleId = :roleid");
        q.setParameter("roleid", i);
      
        listac = q.getResultList();
        return listac;
    }
    public List<Account> Alluser() {
         List<Account> listac = new ArrayList<Account>();
        Query q = em.createQuery("SELECT a FROM Account a WHERE a.cMSRole.roleId > :roleid");
        q.setParameter("roleid", 1);
        listac = q.getResultList();
        return listac;

    }
    public AccountFacade() {
        super(Account.class);
    }
}
